<?php

class CLog
{
    public function write($msg, $msg_type='', $log_type='system', $file_name='savage-errors.log')
    {
        if (is_object($msg) or is_array($msg))
        {
            $msg = json_encode($msg);
        }
        $to_file = (($msg_type=='')?'':$msg_type.': ').$msg;

        $trace_array=debug_backtrace();
        foreach($trace_array as $trace)
        {
            if(isset($trace['file'],$trace['line']))
            {
                $to_file.="\n".$trace['file'].' ('.$trace['line'].')';
            }
        }
        if ($log_type == 'system')
        {
            error_log($to_file);
        }
        else
        {
            $fp = fopen($file_name, "a");
            fwrite($fp, $to_file);
            fclose($fp);
        }

    }
}
